home *** CD-ROM | disk | FTP | other *** search
- real maxVal, lastReset;
- real maxContents, maxTime;
- real timeArray[];
- integer initFlag, resetCon;
- integer discrete, newInput;
-
- ** This block accumulates input values
- ** Copyright © 1989-1994 by Imagine That, Inc.
- ** All Rights Reserved.
- ** Extend Generic Library, Accumulate block; Alfy Riddle
- ** modified 3/1/92 JSL extensively modified for V2.0
- ** 12/8/92 JSL added (currentStep == 0 && !resetCon)
- ** 2/26/93 JSL conOut only recalcs if not from plotter
- ** 7/20/93 JSL added if (!newInput) to on conOut
- // 10/27/93 BD fixed animation level
- // 2/14/94 DJK modified trace and report
- // 3/10/94 DJK added block label to trace & report
- // 5/18/94 BD changed dialog, help
-
-
- procedure calc()
- {
- real newVal;
-
- ** for initialization and resets
- if (((currentStep == 0 && !resetCon) || resetIn > 0.5) && lastReset != currentTime)
- {
- if( initFlag )
- {
- if( noValue(initIn) )
- {
- userError("BLANK value at Accumulate block s input.");
- abort;
- }
- accum = initIn; ** use connector for starting value if connected
- startVal = accum;
- }
- else
- accum = startVal; ** use dialog box value
-
- lastReset = currentTime;
- }
-
- if (!discrete || newInput)
- newVal = ConIn;
- else
- newVal = 0.0;
- newInput = FALSE;
-
- ** make sure valid data (blanks contaminate data)
- if( !noValue(ConIn) )
- {
- accum = accum + newVal;
-
- if (accum > maxVal) // increase maximum if necessary
- maxVal = accum;
- if (accum > maxContents) // this will remember a smaller max level
- maxContents = accum; // remember max level from this run
-
- animationShow(1);
- if (maxVal <= 0.0)
- animationLevel(1, 0);
- else
- animationLevel(1, accum/ maxVal);
- }
-
- conOut = accum;
-
- ** sysGlobal2 is the file reference number for the DEBUG TRACE
- if( sysGlobal2 != 0.0 ) ** 0 is error, check for open file for TRACE
- {
- // template for report: |BLOCK NAME *****************|block number |BLOCK NUMBER*******
- fileWrite(sysGlobal2,"Accumulator block number "+(MyBlockNumber())+". Current Time:"+currentTime+".","",True);
- if(getBlockLabel(myBlockNumber()) != "")
- fileWrite(sysGlobal2,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
- fileWrite(sysGlobal2," Input = "+conIn,"",True);
- fileWrite(sysGlobal2," Contents = "+conOut,"",True);
- fileWrite(sysGlobal2," Start Input = "+initIn,"",True);
- fileWrite(sysGlobal2," Reset Input = "+resetIn,"",True);
- fileWrite(sysGlobal2," ","",True);
- }
- }
-
-
- // These connector messages are only called when this block is used in a
- // Discrete Event Model.
-
- on ConIn
- {
- newInput = TRUE;
- sendMsgToOutputs(initIn);
- sendMsgToOutputs(resetIn);
- calc();
- sendMsgToInputs(conOut);
- }
-
- // These connector messages are only called when this block is used in a
- // Discrete Event Model.
-
- on ConOut
- {
- // if the message is not coming from a plotter
- if (sysGlobalint9 == 0)
- {
- if (!newInput)
- sendMsgToOutputs(conIn);
- sendMsgToOutputs(initIn);
- sendMsgToOutputs(resetIn);
- calc();
- }
- }
-
- // These connector messages are only called when this block is used in a
- // Discrete Event Model.
-
- on initIn
- {
- sendMsgToOutputs(conIn);
- sendMsgToOutputs(resetIn);
- calc();
- sendMsgToInputs(conOut);
- }
-
- // These connector messages are only called when this block is used in a
- // Discrete Event Model.
-
- on resetIn
- {
- lastReset = -1.0;
- sendMsgToOutputs(conIn);
- sendMsgToOutputs(initIn);
- calc();
- sendMsgToInputs(conOut);
- }
-
-
- ** This message occurs for each step in the simulation.
- on Simulate
- {
- calc();
- }
-
-
- ** If the dialog data is inconsistent for simulation, abort.
- on checkData
- {
- sysGlobal1 = 0.0; ** prevent false reports
- sysGlobal2 = 0.0; ** prevent false debugs
-
- resetCon = resetIn;
-
- if( initIn )
- initFlag = 1;
- else
- initFlag = 0;
-
- if( noValue(startVal) AND !initFlag )
- {
- userError("Accumulate block needs a starting value");
- abort;
- }
- }
-
-
- ** Initialize any simulation variables.
- on initSim
- {
- accum = startVal;
-
- maxVal = maxContents; // start from max remembered from last run
- if (maxVal == 0.0)
- maxVal = startVal;
-
- animationLevel(1, 0);
- animationColor(1, 30000, 30000, 30000, 1);
- if (animationOn)
- animationShow(1);
- else
- animationHide(1, FALSE);
-
- maxTime = endTime - startTime;
- maxContents = 0.0;
- lastReset = -1.0;
-
- discrete = FALSE;
- if( getPassedArray(sysGlobal0, timeArray) )
- {
- discrete = TRUE;
- getSimulateMsgs(FALSE);
- }
- }
-
-
- on createBlock
- {
- startVal = 0;
- maxVal = 0.0;
- maxContents = 0.0;
- }
-
-
- on endSim
- {
- ** sysGlobal1 is the file reference number for the TEXT REPORT
- if( sysGlobal1 != 0.0 ) ** 0 is error, check for open file for REPORT
- {
- // template for report: |BLOCK NAME *****************|block number |BLOCK NUMBER*******
- fileWrite(sysGlobal1,"Accumulator block number "+(MyBlockNumber()),"",True);
- if(getBlockLabel(myBlockNumber()) != "")
- fileWrite(sysGlobal1,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
- fileWrite(sysGlobal1," Starting Contents = "+startVal,"",True);
- fileWrite(sysGlobal1," Final Contents = "+accum,"",True);
- if( comments != "" )
- fileWrite(sysGlobal1," Comments = "+comments,"",True);
- fileWrite(sysGlobal1," ","",True);
- }
- }